package com.cskaoyan.service.wx.impl;

import com.cskaoyan.bean.pojo.Region;
import com.cskaoyan.bean.pojo.RegionExample;
import com.cskaoyan.bean.wx.region.vo.RegionVo;
import com.cskaoyan.mapper.RegionMapper;
import com.cskaoyan.service.wx.WxRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @Name : WxRegionServiceImpl.java
 * @Time : 2021/8/14 22:44
 * @Author : creamycandy
 * @Software : IntelliJ IDEA
 */
@Transactional
@Service
public class WxRegionServiceImpl implements WxRegionService {

    @Autowired
    RegionMapper regionMapper;

    @Override
    public List<RegionVo> getRegionVo(Integer pid) {
        RegionExample regionExample = new RegionExample();
        RegionExample.Criteria criteria = regionExample.createCriteria();
        criteria.andPidEqualTo(pid);
        List<Region> regions = regionMapper.selectByExample(regionExample);
        List<RegionVo> regionVos = new ArrayList<>();
        for (Region region : regions) {
            RegionVo regionVo = new RegionVo();
            regionVo.setId(region.getId());
            regionVo.setPid(region.getPid());
            regionVo.setName(region.getName());
            regionVo.setType(region.getType());
            regionVo.setCode(region.getCode());
            regionVos.add(regionVo);
        }
        return regionVos;
    }
}
